package com.my.tool.lucky.model;

import org.springframework.util.StringUtils;

import java.util.List;
import java.util.stream.Collectors;

public class Gift {

    private List<Integer> red = null;
    private List<Integer> blue = null;

    private String redTxt;
    private String blueTxt;

    public static Gift of() {
        return new Gift();
    }

    public static Gift of(List<Integer> hengKeys, List<Integer> haKey) {
        Gift gift = new Gift();
        gift.red = hengKeys;
        gift.blue = haKey;
        return gift;
    }

    public List<Integer> getRed() {
        return red;
    }

    public void setRed(List<Integer> red) {
        this.red = red;
    }

    public List<Integer> getBlue() {
        return blue;
    }

    public void setBlue(List<Integer> blue) {
        this.blue = blue;
    }

    public String getRedTxt() {
        if(!StringUtils.hasText(redTxt)) {
            redTxt = red.stream().sorted().map(String::valueOf).collect(Collectors.joining(", "));
        }
        return redTxt;
    }

    public String getBlueTxt() {
        if(!StringUtils.hasText(blueTxt)) {
            blueTxt = blue.stream().sorted().map(String::valueOf).collect(Collectors.joining(", "));
        }
        return blueTxt;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("Gift{");
        sb.append("red=").append(red);
        sb.append(", blue=").append(blue);
        sb.append('}');
        return sb.toString();
    }
}
